package org.example.javassist;

import javassist.*;
import org.example.Base;

import java.io.IOException;

/**
 * @author : yuhuan.wu
 * @date : 2021/10/27
 * @description :
 */
public class JavassistTest {
    public static void main(String[] args) throws NotFoundException, CannotCompileException, IllegalAccessException, InstantiationException, IOException, NotFoundException {
        ClassPool cp = ClassPool.getDefault();
        CtClass cc = cp.get("com.cc.mathAndStructure.unUserfulTest.BaseB");
        CtMethod m = cc.getDeclaredMethod("process");
        m.insertBefore("{ System.out.println(\"start\"); }");
        m.insertAfter("{ int j = 2; System.out.println(j);}");
//        m.insertAfter("{ System.out.println(j); }");
        Class c = cc.toClass();
//        cc.writeFile("/Users/zen/projects");
        cc.writeFile("D:\\GOWORK\\MyAllProject\\math-and-structure\\target\\classes");

        Base h = (Base)c.newInstance();
        h.process();
    }
}
